package root

import (
	"os"
	"os/exec"
	"syscall"
)

// New create container
func New(imageDir string, args []string) *Container {
	cmd := exec.Command("/proc/self/exe")
	cmd.Args = append(cmd.Args, "_run", "-i", imageDir)
	cmd.Args = append(cmd.Args, args...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.SysProcAttr = &syscall.SysProcAttr{
		Cloneflags: syscall.CLONE_NEWNS |
			syscall.CLONE_NEWUTS |
			syscall.CLONE_NEWPID,
		Unshareflags: syscall.CLONE_NEWNS,
	}
	return &Container{
		cmd: cmd,
	}
}
